/*
 * NewsManagerBean.java
 *
 * Created on 25 wrzesień 2007, 23:18
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package info.mikrotubula.managers;

import info.mikrotubula.db.News;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Krystian
 */
@Stateless
public class NewsManagerBean implements info.mikrotubula.managers.NewsManagerLocal {
    
    @PersistenceContext(unitName = "persistence")
    protected EntityManager em;
    
    /** Creates a new instance of NewsManagerBean */
    public NewsManagerBean() {
    }
    
    public List<News> list() {
        return (List<News>) em.createNamedQuery("News.findAll").getResultList();
    }
    
    public News create(News news) {
        try {
            em.persist(news);
        } catch (Exception ex) {
            ex.printStackTrace();
        } 
        return news;
    }
    
    public void delete(News news) {
        try {
            em.remove(news);
        } catch (Exception ex) {
            ex.printStackTrace();
        } 
    }
}
